﻿/***************************************************************************
创建者：华磊
 开始时间：               : 2020.11.29
 copyright            : (C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   主菜单窗口程序
*                                                                         *
 ***************************************************************************/
#include "../CommunicateDelegate/communicatenormaldelegate.h"
#include "homemenudelegate.h"
#include <QDebug>
#include <QMessageBox>
#include "../DomParser/domparser.h"
#include "../FtpManage/ftpmanage.h"
#include "../FileManage/filemanage.h"
#include "../CommunicateDelegate/filedata.h"
#include "hmicommondefine.h"
#include "instructionEnum.h"
#include "weldpropertydialog.h"
#include "weldconditiondialog.h"
#include "weldsystemdialog.h"

#include "restoredialog.h"
#include "restoreandbackupdlg.h"
#include "upgradehmiexedlg.h"
#include "filebackupdialog.h"
#include "filerestoredialog.h"


extern FileData fileData;

extern FtpManage *ftpManage;

HomeMenuDelegate::HomeMenuDelegate(HomeMenuView *homeMenuViewIn,  GlobalData *globalDataIn,MoveOperation *moveOperationIn,
                                   CommunicateNormalDelegate *communicateNormalDelegateIn,QObject* parent):QObject(parent)
{
    homeMenuView = homeMenuViewIn;
    globalData = globalDataIn;
    moveOperation = moveOperationIn;
    communicateNormalDelegate=communicateNormalDelegateIn;

    motorStatusFlag = true;

    initCoordInfoData = true;

    timer = new QTimer;
    connect(timer, SIGNAL(timeout()), this, SLOT(realTimeSlot()));

    robotSize = 0;

    //执行 还原 备份时候用的
    systemCmdDelegate = new SystemCmdDelegate;
    systemCmdDelegate->moveToThread(&cmdThread);
    cmdThread.start();

    //关机
    shutDownTimer = new QTimer;
    shutDownFlag = 0;
    shutDownS = 5;//默认五秒关机
    connect(shutDownTimer,SIGNAL(timeout()),this,SLOT(shutDownStartTimeSlot()));

//    isPasswordCorrectFlag=false;
//    passCheckDlg=new PasswordCheckDialog();
//    //passCheckDlg->setGeometry(70,128,460,595);
//    passCheckDlg->move(70,128);
//    passCheckDlg->hide();
//    passCheckDlg->setParent(this);
//    connect(passCheckDlg,SIGNAL(passWordState(bool)),this,SLOT(passWordCheckSlot(bool)));
    initConnect();
}

HomeMenuDelegate::~HomeMenuDelegate()
{

}

void HomeMenuDelegate::initConnect()
{
    //按钮
    connect(homeMenuView->fileAction[0],SIGNAL(triggered()),this,SLOT(showBackupSlot()));
    connect(homeMenuView->fileAction[1],SIGNAL(triggered()),this,SLOT(showRecoverySlot()));
    connect(homeMenuView->fileAction[2],SIGNAL(triggered()),this,SLOT(showStorageStatusSlot()));
    connect(homeMenuView->fileAction[3],SIGNAL(triggered()),this,SLOT(showRestoreAndBackupDlgSlot()));
    connect(homeMenuView->fileAction[4],SIGNAL(triggered()),this,SLOT(showFileManage_Slot()));

    connect(homeMenuView->roleAction[0],SIGNAL(triggered()),this,SLOT(showUserChangeSlot()));
    connect(homeMenuView->roleAction[1],SIGNAL(triggered()),this,SLOT(showPasswordChangeSlot()));

    connect(homeMenuView->runConfigAction[0],SIGNAL(triggered()),this,SLOT(showCoordinateSlot()));
    connect(homeMenuView->runConfigAction[1],SIGNAL(triggered()),this,SLOT(showManualServonSlot()));
    connect(homeMenuView->runConfigAction[2],SIGNAL(triggered()),this,SLOT(showTouchCorrectSlot()));
    connect(homeMenuView->runConfigAction[3],SIGNAL(triggered()),this,SLOT(showIPSetSlot()));
    connect(homeMenuView->runConfigAction[4],SIGNAL(triggered()),this,SLOT(showAdditionLoadSlot()));
    connect(homeMenuView->runConfigAction[5],SIGNAL(triggered()),this,SLOT(showSecurePointSlot()));
    connect(homeMenuView->runConfigAction[6],SIGNAL(triggered()),this,SLOT(showInterferenceAreaSlot()));
    connect(homeMenuView->runConfigAction[7],SIGNAL(triggered()),this,SLOT(showEtherSlot()));
    connect(homeMenuView->runConfigAction[8],SIGNAL(triggered()),this,SLOT(showRSR1Slot()));
    connect(homeMenuView->runConfigAction[9],SIGNAL(triggered()),this,SLOT(showSoftLimitSlot()));
    connect(homeMenuView->runConfigAction[10],SIGNAL(triggered()),this,SLOT(showOtherSettingDlgSlot()));

    connect(homeMenuView->monitorAction[0],SIGNAL(triggered()),this,SLOT(showAreaOffsetSlot()));
    connect(homeMenuView->monitorAction[1],SIGNAL(triggered()),this,SLOT(showDebugDlgSlot()));
    connect(homeMenuView->monitorAction[2],SIGNAL(triggered()),this,SIGNAL(showFleetDebugView_signal()));


    connect(homeMenuView->logAction[0],SIGNAL(triggered()),this,SLOT(showDevLogSlot()));

    connect(homeMenuView->shutdownAction[0],SIGNAL(triggered()),this,SLOT(showColdStartSlot()));
//    connect(homeMenuView->act5[1],SIGNAL(triggered()),this,SLOT(showHotStartSlot()));

    connect(homeMenuView->helpAction[0],SIGNAL(triggered()),this,SLOT(showCompanyInformationSlot()));
    connect(homeMenuView->helpAction[1],SIGNAL(triggered()),this,SLOT(showSoftwareInformationSlot()));
    connect(homeMenuView->helpAction[2],SIGNAL(triggered()),this,SLOT(showRegisterSlot()));
    connect(homeMenuView->helpAction[3],SIGNAL(triggered()),this,SLOT(showRestoreSlot()));
    connect(homeMenuView->helpAction[4],SIGNAL(triggered()),this,SLOT(showRestoreFromPcSlot()));


    connect(homeMenuView->advanceAction[0],SIGNAL(triggered()),this,SLOT(showCalibrateDlgSlot()));
    connect(homeMenuView->advanceAction[1],SIGNAL(triggered()),this,SLOT(showRobotTopologySlot()));
    connect(homeMenuView->advanceAction[2],SIGNAL(triggered()),this,SLOT(showECATTopologySlot()));
    connect(homeMenuView->advanceAction[3],SIGNAL(triggered()),this,SLOT(showDIDOMappingSlot()));
    connect(homeMenuView->advanceAction[4],SIGNAL(triggered()),this,SLOT(showRobotConfigSlot()));
    connect(homeMenuView->advanceAction[5],SIGNAL(triggered()),this,SLOT(showVrepConfigSlot()));

    connect(homeMenuView->languageAction[0],SIGNAL(triggered()),this,SLOT(showProEditLanguage0Slot()));
    connect(homeMenuView->languageAction[1],SIGNAL(triggered()),this,SLOT(showProEditLanguage1Slot()));

    connect(homeMenuView->action_craft[0],SIGNAL(triggered()),this,SIGNAL(showBeltTrackView_signal()));
    connect(homeMenuView->action_craft[1],SIGNAL(triggered()),this,SIGNAL(showWeldPropertyView_signal()));
    connect(homeMenuView->action_craft[2],SIGNAL(triggered()),this,SIGNAL(showWeldConditionView_signal()));
    connect(homeMenuView->action_craft[3],SIGNAL(triggered()),this,SIGNAL(showWaveMotionConditionView_signal()));
    connect(homeMenuView->action_craft[4],SIGNAL(triggered()),this,SIGNAL(showWeldSystemConfigView_signal()));
    connect(homeMenuView->action_craft[5],SIGNAL(triggered()),this,SIGNAL(showLaserCameraConfigView_signal()));
    connect(homeMenuView->action_craft[6],SIGNAL(triggered()),this,SIGNAL(showCoupleControlView_signal()));
    connect(homeMenuView->action_craft[7],SIGNAL(triggered()),this,SIGNAL(showPalletSettingView_signal()));

    //子页面-事件处理
    connect(homeMenuView->manualServonDialog,SIGNAL(servonBtnSignals(int)),this,SLOT(manualChangeBtnSlot(int)));
    connect(homeMenuView,SIGNAL(servonBtnSignals(int)),this,SLOT(manualChangeBtnSlot(int)));

    connect(homeMenuView->setZeroPointDialog,SIGNAL(calibrateAllAxisSignal()),this,SLOT(setCaliberBtnSlot()));
    connect(homeMenuView->setZeroPointDialog,SIGNAL(calibrateOneAxisSignal(int)),this,SLOT(calibrateOneAxisSlot(int)));
    connect(homeMenuView->setZeroPointDialog,SIGNAL(allowCalibrateJogSignal(bool)),this,SLOT(allowCalibrateJogSlot(bool)));
    connect(homeMenuView->setZeroPointDialog,SIGNAL(getCalibrateInformation()),this,SLOT(getCalibrateInformationSlot()));

    connect(homeMenuView->setZeroPointDialog,SIGNAL(recordPoint_signal()),this,SLOT(recordPoint_slot()));
    connect(homeMenuView->setZeroPointDialog,SIGNAL(clearPoint_signal()),this,SLOT(clearPoint_slot()));
    connect(homeMenuView->setZeroPointDialog,SIGNAL(calculateZero_signal()),this,SLOT(calculateZero_slot()));
    connect(homeMenuView->setZeroPointDialog,SIGNAL(setZeroOffset_signal()),this,SLOT(setZeroOffset_slot()));

    connect(homeMenuView->motorStatusView,SIGNAL(startWaveForm()),this,SLOT(startWaveFormSlot()));
    connect(homeMenuView->motorStatusView,SIGNAL(ceaseWaveForm()),this,SLOT(ceaseWaveFormSlot()));

    connect(homeMenuView->setcoordinatedialog,SIGNAL(selectToolCoordinate()),this,SLOT(selectToolCoordinateSlot()));
    connect(homeMenuView->setcoordinatedialog,SIGNAL(selectUserCoordinate()),this,SLOT(selectUserCoordinateSlot()));
    connect(homeMenuView->setcoordinatedialog,SIGNAL(reloadCoordinate()),this,SLOT(reloadCoordinateData()));
    connect(homeMenuView->coordinate2Dialog,SIGNAL(recordPoint(int,int,int)),this,SLOT(recordPointSlot(int,int,int)));
    connect(homeMenuView->coordinate2Dialog,SIGNAL(calculateCoordinate(int,int)),this,SLOT(calculateCoordinateSlot(int,int)));
    connect(homeMenuView->coordinate2Dialog,SIGNAL(moveToCoordinatePointPress(MoveParameter)),this,SLOT(moveToCoordinatePointPressSlot(MoveParameter)));
    connect(homeMenuView->coordinate2Dialog,SIGNAL(moveToCoordinatePointRelease()),this,SLOT(moveToCoordinatePointReleaseSlot()));
    connect(homeMenuView->coordinate2Dialog,SIGNAL(setToolMass_signal(int , double ,QVector<double> )),
                                            this,SLOT(setToolMass_slot(int , double ,QVector<double>)));


	connect(homeMenuView->fileRestoreDialog,SIGNAL(restoreFile(QString)),this,SLOT(restoreFileSlot(QString)));
    connect(this,SIGNAL(systemCmdRestoreSignal(QString)),systemCmdDelegate,SLOT(systemCmdRestore(QString)));

    connect(homeMenuView->fileBackUpDialog,SIGNAL(backupFile(int,int,int,int,int,QVector<RobotBackUpInformation>,QString)),this,SLOT(backupFileSlot(int,int,int,int,int,QVector<RobotBackUpInformation>,QString)));
    connect(this,SIGNAL(systemCmdBackupAllSignal(QString)),systemCmdDelegate,SLOT(systemCmdBackupAll(QString)));
    connect(this,SIGNAL(systemCmdBackupGlobalSignal(QString)),systemCmdDelegate,SLOT(systemCmdBackupGlobal(QString)));
    connect(this,SIGNAL(systemCmdBackupProgramSignal(QString,int)),systemCmdDelegate,SLOT(systemCmdBackupProgram(QString,int)));
    connect(this,SIGNAL(systemCmdBackupDatSignal(QString,int)),systemCmdDelegate,SLOT(systemCmdBackupDat(QString,int)));
    connect(this,SIGNAL(systemCmdBackupConfigSignal(QString,int)),systemCmdDelegate,SLOT(systemCmdBackupConfig(QString,int)));

    connect(homeMenuView->registrationDialog,SIGNAL(registrateSignal(QString)),this,SLOT(registrateSlot(QString)));
    connect(homeMenuView->registrationDialog,SIGNAL(registrateFileSignal(QString)),this,SLOT(registrateFromFileSlot(QString)));

    connect(homeMenuView->deviceLogDialog,SIGNAL(showCurrentRobotMessage()),this,SLOT(showCurrentRobotMessageSlot()));
    connect(homeMenuView->deviceLogDialog,SIGNAL(showAllRobotMessage()),this,SLOT(showAllRobotMessageSlot()));
    connect(homeMenuView->deviceLogDialog,SIGNAL(errorMessageShowOrHide(int)),this,SLOT(errorMessageShowOrHideSlot(int)));
    connect(homeMenuView->deviceLogDialog,SIGNAL(warnMessageShowOrHide(int)),this,SLOT(warnMessageShowOrHideSlot(int)));
    connect(homeMenuView->deviceLogDialog,SIGNAL(noteMessageShowOrHide(int)),this,SLOT(noteMessageShowOrHideSlot(int)));
    connect(homeMenuView->deviceLogDialog,SIGNAL(waitMessageShowOrHide(int)),this,SLOT(waitMessageShowOrHideSlot(int)));
    connect(homeMenuView->deviceLogDialog,SIGNAL(startDateChanged(QDate)),this,SLOT(startDateChangedSlot(QDate)));
    connect(homeMenuView->deviceLogDialog,SIGNAL(endDateChanged(QDate)),this,SLOT(endDateChangedSlot(QDate)));

    connect(homeMenuView->ipSettingDialog, SIGNAL(setHmiIp(QVector<int>,QVector<int>,QVector<int>)), this, SLOT(setHmiIpSlot(QVector<int>,QVector<int>,QVector<int>)));
    connect(homeMenuView->ipSettingDialog, SIGNAL(setControllerIp(QVector<int>,QVector<int>,QVector<int>)), this, SLOT(setControllerIpSlot(QVector<int>,QVector<int>,QVector<int>)));

    connect(homeMenuView->passwordModiyDialog,SIGNAL(modifySignal()),this,SLOT(modifySlot()));

    connect(homeMenuView->startTypeDialog,SIGNAL(setStartTypeSignal(int)),this,SLOT(setStartTypeSlot(int)));
    connect(homeMenuView->startTypeDialog,SIGNAL(setShutDownSiganl()),this,SLOT(setShutDownSlot()));
    connect(homeMenuView->startTypeDialog,SIGNAL(controlShutDownEnable(bool)),this,SLOT(controllerShutDownEnableSlot(bool)));

    connect(homeMenuView->restoreCheckDialog,SIGNAL(hmiUpdatePathSignal(QString)),this,SLOT(hmiUpdatePathSlot(QString)));
    connect(homeMenuView->restoreCheckDialog,SIGNAL(hmiRestoreSignal()),this,SLOT(hmiRestoreSlot()));
    connect(homeMenuView->restoreCheckDialog,SIGNAL(ctrlUpdatePathSignal(QString)),this,SLOT(ctrlUpdatePathSlot(QString)));
    connect(homeMenuView->restoreCheckDialog,SIGNAL(ctrlRestoreSignal()),this,SLOT(ctrlRestoreSlot()));


    connect(homeMenuView->vrepConfigView,SIGNAL(signal_connectVrep(QString, int)),this,SIGNAL(signal_connectVrep(QString, int)));
    connect(homeMenuView->vrepConfigView,SIGNAL(signal_disconnectVrep()),this,SIGNAL(signal_disconnectVrep()));
    connect(homeMenuView->vrepConfigView,SIGNAL(signal_setVrepServoType(int)),this,SIGNAL(signal_setVrepServoType(int)));
    connect(homeMenuView->vrepConfigView,SIGNAL(signal_setVrepIoType(int)),this,SIGNAL(signal_setVrepIoType(int)));

    //hualei add
    connect(homeMenuView->debugInfoDlg,SIGNAL(getMotionEngineDebugInfoSignal()),this,SLOT(getMotionEngineDebugInfoSlot()));
    connect(homeMenuView->debugInfoDlg,SIGNAL(getPogramEngineDebugInfoSignal()),this,SLOT(getPogramEngineDebugInfoSlot()));
    connect(homeMenuView->debugInfoDlg,SIGNAL(getTaskInfoSignal()),this,SLOT(getTaskInfoSlot()));

    connect(homeMenuView->ethercatDevicefigDlg,SIGNAL(getEthercatSlavesInformationSignal()),this,SLOT(getEthercatSlavesInformationSlot()));
    connect(homeMenuView->ethercatDevicefigDlg,SIGNAL(writeEthercatDeviceAliasSignal(int,int)),this,SLOT(writeEthercatDeviceAliasSlot(int,int)));
    connect(homeMenuView->ethercatDevicefigDlg,SIGNAL(clearMotorBatteryErrorSignal()),this,SLOT(clearMotorBatteryErrorSlot()));
    connect(homeMenuView->ethercatDevicefigDlg,SIGNAL(setMotorDcModeSignal(int)),this,SLOT(setMotorDcModeSlot(int)));

    connect(homeMenuView->weldPropertyDialog,SIGNAL(showErrorMsgBox(QString)),this,SLOT(showWeldPropetyViewErrorMsg(QString)));
    connect(homeMenuView->weldConditionDialog,SIGNAL(showErrorMsgBox(QString)),this,SLOT(showWeldPropetyViewErrorMsg(QString)));
    connect(homeMenuView->weldSystemDialog,SIGNAL(showErrorMsgBox(QString)),this,SLOT(showWeldPropetyViewErrorMsg(QString)));
    //    connect(ftpManage, SIGNAL(getFileInServerDirectory(QHash<QString,bool>,QString,QString)), \
//            this, SLOT(getLogFileDirSlot(QHash<QString,bool>,QString,QString)));
//    connect(ftpManage, SIGNAL(isGetFile(bool,QString)), this, SLOT(getFileSlot(bool,QString)));
}

void HomeMenuDelegate::showBackupSlot()
{
    qDebug()<<"systemdisk";
//    homeMenuView->fileBackUpDialog->show();
//    showBackupView();
}

void HomeMenuDelegate::showWeldPropetyViewErrorMsg(QString msg){
     emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),msg);
}
void HomeMenuDelegate::showRecoverySlot()
{
    qDebug()<<"recovery";
//    homeMenuView->fileRestoreDialog->show();
}

void HomeMenuDelegate::showStorageStatusSlot()
{
    qDebug()<<"storagestatus";
}

void HomeMenuDelegate::showRestoreAndBackupDlgSlot()
{
    qDebug()<<"showRestoreAndBackupDlgSlot";
    PasswordCheckDialog passCheckDlg;
    //passCheckDlg->setGeometry(70,128,460,595);
    passCheckDlg.move(70,128);
    passCheckDlg.setModal(false);
    passCheckDlg.show();
    int res= passCheckDlg.exec();
    if (res ==QDialog::Accepted)
    {
    //  QMessageBox::about(NULL, "提示", "您点击了OK按钮！");
        homeMenuView->restoreAndBackDlg->show();
    }
    if (res ==QDialog::Rejected)
    {
    //  QMessageBox::about(NULL, "提示", "您点击了关闭按钮！");
       //添加关闭时你要的行为
    }

}

void HomeMenuDelegate::showFileManage_Slot()
{
    qDebug() << "Show FileManage View!";
    emit showFileManage_Signal();
}

void HomeMenuDelegate::showUserChangeSlot()
{
//    globalData->lock();
    globalData->controllerIsConnected = EM_CONNECT_END;
    globalData->globalLoginStatus = false;
//    globalData->unlock();

    homeMenuView->showLoginView();
}

void HomeMenuDelegate::showPasswordChangeSlot()
{
//    if(globalData->tryLock(TRYLOCKTIME))
//    {
    UserInfo userInfo=globalData->getUserInfo();
    homeMenuView->passwordModiyDialog->show();
    homeMenuView->passwordModiyDialog->userAccount=userInfo.account;
    homeMenuView->passwordModiyDialog->changeAccount=userInfo.account;
    homeMenuView->passwordModiyDialog->userPassword = QString::fromStdString(userInfo.password);
    homeMenuView->passwordModiyDialog->updateView();

//        globalData->unlock();
//    }
}

void HomeMenuDelegate::showColdStartSlot()
{
    qDebug()<<"coldstart";
    homeMenuView->startTypeDialog->show();
    homeMenuView->startTypeDialog->updateView(0);//冷启动

}

void HomeMenuDelegate::showHotStartSlot()
{
    qDebug()<<"hotstart";
    homeMenuView->startTypeDialog->show();
    homeMenuView->startTypeDialog->updateView(1);//热启动
}

void HomeMenuDelegate::showCompanyInformationSlot()
{
    qDebug()<<"companyinformation";
    std::string imageStrOut;
    if(EM_CONNECT_SUCCESS==globalData->controllerIsConnected)
    {
            communicateNormalDelegate->getImageStringFormImagePath(D_COMPANY_INFO_IMAGE_PATH,imageStrOut);
    }
    homeMenuView->companyInfoDialog->updateCompanyPictureShow(imageStrOut);
    homeMenuView->companyInfoDialog->show();
}

void HomeMenuDelegate::showSoftwareInformationSlot()
{
    qDebug()<<"softwareinformation";
    homeMenuView->copyRightDialog->show();

    QSettings settings(VERSION_INI_PATH, QSettings::IniFormat);

    ComponentVersion tmp;
    homeMenuView->copyRightDialog->hmiComponentVersionList.clear();
    int count =settings.value("info/count").toInt();

    for(int i = 1;i<=count;i++)
    {
        tmp.componentName = settings.value(QString::number(i)+"/name").toString().toStdString();
        tmp.componentVersion = settings.value(QString::number(i)+"/version").toString().toStdString();
        tmp.publishDate = settings.value(QString::number(i)+"/time").toString().toStdString();
        homeMenuView->copyRightDialog->hmiComponentVersionList.append(tmp);
    }

    //
    homeMenuView->copyRightDialog->controllerComponentVersionList.clear();
//    if(globalData->tryLock(TRYLOCKTIME))
//    {
    std::vector<ComponentVersion> componentVersionListOut;
    globalData->getVersionList(componentVersionListOut);
        for(int i =0;i<componentVersionListOut.size();i++)
        {
            homeMenuView->copyRightDialog->controllerComponentVersionList.append(componentVersionListOut[i]);
        }

//        globalData->unlock();
//    }

    homeMenuView->copyRightDialog->updateView();
}

void HomeMenuDelegate::showRegisterSlot()
{
    qDebug()<<"register";
    homeMenuView->registrationDialog->show();
    if(globalData)
    {
//        if(globalData->tryLock(TRYLOCKTIME))
//        {
            homeMenuView->registrationDialog->serialNumber = QString::fromStdString(globalData->getSerialNumber());//序列号
            homeMenuView->registrationDialog->expireTime = QString::fromStdString(globalData->getGlobalLockMachTime());//锁机时间
            homeMenuView->registrationDialog->currentTime = QString::fromStdString(globalData->getCurrentTime());//当前时间
            QString tmp = QString::fromStdString(globalData->getSerialNumber());
            if(30 == tmp.size())
            {
                //homeMenuView->registrationDialog->registrationString.clear();
                if(6 == homeMenuView->registrationDialog->registrationString.size())
                {
                    for(int i = 0;i<6;i++)
                    {
                        homeMenuView->registrationDialog->registrationString[i] = tmp.mid(i*5,5);
                    }
                }
            }

            int tmpReg = globalData->globalRegStatus;//注册状态

//            globalData->unlock();

            if(tmpReg == ENUM_TIME_NORMAL)//100
            {
                homeMenuView->registrationDialog->registrationStatus = tr("注册有效");
            }
            else if(tmpReg == ENUM_TIME_GOING_PASSED)
            {
                homeMenuView->registrationDialog->registrationStatus = tr("注册有效(不足一周即将过期)");
            }
            else if(tmpReg == ENUM_TIME_PASSED)
            {
                homeMenuView->registrationDialog->registrationStatus = tr("已过期");
            }
            else if(tmpReg == ENUM_SERIAL_UNEQUAL)//103
            {
                homeMenuView->registrationDialog->registrationStatus = tr("序列号不正确");
            }

            else if(tmpReg == ENUM_REGISTER_NO_EXIST)
            {
                homeMenuView->registrationDialog->registrationStatus = tr("注册码不存在");
            }
            else if(tmpReg == ENUM_REGISTER_FILE_NODE_ERROR)
            {
                homeMenuView->registrationDialog->registrationStatus = tr("注册文件格式错误，缺少信息");
            }
            else if(tmpReg == ENUM_REGISTER_FILE_CHECK_CODE_ERROR)
            {
                homeMenuView->registrationDialog->registrationStatus = tr("注册文件校验码不对应错误");
            }
            else if(tmpReg == ENUM_BOOT_COUNT_EXCEED)
            {
                homeMenuView->registrationDialog->registrationStatus = tr("注册码超过允许启动次数");
            }
            else
            {
                homeMenuView->registrationDialog->registrationStatus = tr("未知授权信息类型=")+ QString::number(tmpReg);
            }
            homeMenuView->registrationDialog->updateView();
//        }
    }
}

void HomeMenuDelegate::showRestoreSlot()
{
    qDebug()<<"restore";
//    homeMenuView->restoreDialog->show();
}

void HomeMenuDelegate::showRestoreFromPcSlot()
{
    qDebug()<<"showRestoreFromPcSlot";
    PasswordCheckDialog passCheckDlg;
    //passCheckDlg->setGeometry(70,128,460,595);
    passCheckDlg.move(70,128);
    passCheckDlg.setModal(false);
    passCheckDlg.show();
    int res= passCheckDlg.exec();
    if (res ==QDialog::Accepted)
    {
    //  QMessageBox::about(NULL, "提示", "您点击了OK按钮！");
        homeMenuView->upgradeHmiDlg->show();
    }
    if (res ==QDialog::Rejected)
    {
    //  QMessageBox::about(NULL, "提示", "您点击了关闭按钮！");
       //添加关闭时你要的行为
    }


}

void HomeMenuDelegate::showCalibrateDlgSlot()
{
    if(globalData)
    {
        PasswordCheckDialog passCheckDlg;
        //passCheckDlg->setGeometry(70,128,460,595);
        passCheckDlg.move(70,128);
        passCheckDlg.setModal(false);
        passCheckDlg.show();
        int res= passCheckDlg.exec();
        if (res ==QDialog::Accepted)
        {
        //  QMessageBox::about(NULL, "提示", "您点击了OK按钮！");
            homeMenuView->setZeroPointDialog->show();
        }
        if (res ==QDialog::Rejected)
        {
        //  QMessageBox::about(NULL, "提示", "您点击了关闭按钮！");
           //添加关闭时你要的行为
        }

    }
}

void HomeMenuDelegate::showRobotTopologySlot()
{
    qDebug()<<"robottopology";
}

void HomeMenuDelegate::showECATTopologySlot()
{
    qDebug()<<"showECATTopologySlot";
    PasswordCheckDialog passCheckDlg;
    //passCheckDlg->setGeometry(70,128,460,595);
    passCheckDlg.move(70,128);
    passCheckDlg.setModal(false);
    passCheckDlg.show();
    int res= passCheckDlg.exec();
    if (res ==QDialog::Accepted)
    {
    //  QMessageBox::about(NULL, "提示", "您点击了OK按钮！");
        homeMenuView->ethercatDevicefigDlg->show();
    }
    if (res ==QDialog::Rejected)
    {
    //  QMessageBox::about(NULL, "提示", "您点击了关闭按钮！");
       //添加关闭时你要的行为
    }

}

void HomeMenuDelegate::showDIDOMappingSlot()
{
    qDebug()<<"dido";
}

void HomeMenuDelegate::showCoordinateSlot()
{
    //显示
    homeMenuView->setcoordinatedialog->show();

    //2017.03.03 改为直接读取
    if(initCoordInfoData)
    {
        initToolCoordinateData(fileData.toolInfo);
        initUserCoordinateData(fileData.userInfo);

        //initCoordInfoData = false;//应付角色切换的状况
    }
}

void HomeMenuDelegate::showManualServonSlot()
{
    //qDebug()<<"ManualServon";
    homeMenuView->manualServonDialog->show();

    if(globalData)
    {
//        if(globalData->tryLock(TRYLOCKTIME))
//        {
            homeMenuView->manualServonDialog->servonStatus = globalData->globalHandSwitch;
//            globalData->unlock();
//        }
    }
    homeMenuView->manualServonDialog->updateView();
}

void HomeMenuDelegate::showTouchCorrectSlot()
{
    //qDebug()<<"touchcorrect";
    homeMenuView->touchCheckDialog->show();
}

void HomeMenuDelegate::showIPSetSlot()
{
    qDebug()<<"ipset";

    homeMenuView->ipSettingDialog->show();
    if(globalData)
    {
        if(!homeMenuView->ipSettingDialog->initReadFileFlag)//未读文件初始化
        {
            //server ip gate dns
            QSettings settings(CTRL_IP_INI_PATH, QSettings::IniFormat);

            QString ip = settings.value("CtrlIP/ip").toString();
            QString gateway = settings.value("CtrlIP/gateway").toString();
            QString dns = settings.value("CtrlIP/dns").toString();

            homeMenuView->ipSettingDialog->initReadFileCtrl(ip,gateway,dns);

            //hmi ip gate dns
            ip = settings.value("HmiIP/ip").toString();
            gateway = settings.value("HmiIP/gateway").toString();
            dns = settings.value("HmiIP/dns").toString();

            homeMenuView->ipSettingDialog->initReadFileHmi(ip,gateway,dns);

            //end
            homeMenuView->ipSettingDialog->initReadFileFlag = true;
        }

        homeMenuView->ipSettingDialog->updateView();
    }
}

void HomeMenuDelegate::showAdditionLoadSlot()
{
    qDebug()<<"additionload";
}

void HomeMenuDelegate::showSecurePointSlot()
{
    qDebug()<<"securepoint";
}

void HomeMenuDelegate::showInterferenceAreaSlot()
{
    qDebug()<<"interferencearea";
}

void HomeMenuDelegate::showEtherSlot()
{
    qDebug()<<"ether";
}

void HomeMenuDelegate::showRSR1Slot()
{
    qDebug()<<"rsr1";
}

void HomeMenuDelegate::showSoftLimitSlot()
{
    qDebug()<<"showSoftLimitSlot";
}

void HomeMenuDelegate::showOtherSettingDlgSlot()
{
    qDebug()<<"showRestoreAndBackupDlgSlot";
    PasswordCheckDialog passCheckDlg;
    //passCheckDlg->setGeometry(70,128,460,595);
    passCheckDlg.move(70,128);
    passCheckDlg.setModal(false);
    passCheckDlg.show();
    int res= passCheckDlg.exec();
    if (res ==QDialog::Accepted)
    {
    //  QMessageBox::about(NULL, "提示", "您点击了OK按钮！");
        emit showOtherSettingDlgSignal();
    }
    if (res ==QDialog::Rejected)
    {
    //  QMessageBox::about(NULL, "提示", "您点击了关闭按钮！");
       //添加关闭时你要的行为
    }

}

void HomeMenuDelegate::showDevLogSlot()
{
    // 主页界面点击日志按钮响应槽函数
    if(!GSOAP_OPERATE_PROGRAM_FILE_SWITCH)
    {
        if(globalData->isUseFtpOrNfs)
        {
    //        ftpManage->setLoginFileGetFlag(false);
    //        ftpManage->setGetDirFlag(false);
            fileData.ftpOperateNum = EM_FTP_OPERATE_LOGIN;
            ftpManage->getFileInDirectory(D_LOGFILE_PATH,D_LOGFILE_PATH);
        }
    }

    homeMenuView->deviceLogDialog->show();

    if(globalData)
    {
        std::vector<CommRobotInfo> robotInfoListOut;
        globalData->getRobotInfoList(robotInfoListOut);
//        if(globalData->tryLock(TRYLOCKTIME))
//        {
            RobotIdName robotIdNameStruct;
            for(int i = 0; i < robotInfoListOut.size(); i ++)
            {
                robotIdNameStruct.robotId = robotInfoListOut[i].robotId;
                robotIdNameStruct.robotName = QString::fromStdString(robotInfoListOut[i].robotName);

                homeMenuView->deviceLogDialog->robotIdName.push_back(robotIdNameStruct);
            }
            homeMenuView->deviceLogDialog->currentRobotId = globalData->currentRobotID;

//            globalData->unlock();
//        }
    }

    initDeviceLogView();
}

void HomeMenuDelegate::showAreaOffsetSlot()
{
    qDebug()<<"showAreaOffsetSlot";
    homeMenuView->motorStatusView->show();
}

void HomeMenuDelegate::showRobotConfigSlot()
{
    qDebug()<<"showRobotConfigSlot";
    emit showAxisSettingView_signal();
}

void HomeMenuDelegate::showVrepConfigSlot()
{
    qDebug()<<"showVrepConfigSlot";
    homeMenuView->vrepConfigView->show();
}

void HomeMenuDelegate::showProEditLanguage0Slot()
{
    //qDebug()<<"showProEditLanguageSlot";
    emit setEditLanguageSignal(ENUM_LAN_CHINESE);

    //记录进ini文件
    QSettings settings(CTRL_IP_INI_PATH, QSettings::IniFormat); // 当前目录的INI文件
    settings.beginGroup("Login");
    settings.setValue("editLanguage", ENUM_LAN_CHINESE);
    settings.endGroup();

    //
    setEditLanguageChangeMenu(ENUM_LAN_CHINESE);
}

void HomeMenuDelegate::showProEditLanguage1Slot()
{
    //qDebug()<<"showProEditLanguageSlot";
    emit setEditLanguageSignal(ENUM_LAN_ENGLISH);

    //记录进ini文件
    QSettings settings(CTRL_IP_INI_PATH, QSettings::IniFormat); // 当前目录的INI文件
    settings.beginGroup("Login");
    settings.setValue("editLanguage", ENUM_LAN_ENGLISH);
    settings.endGroup();

    //
    setEditLanguageChangeMenu(ENUM_LAN_ENGLISH);
}


//********************子页面内部事件处理部分*********************
bool HomeMenuDelegate::operateAllowFlag()
{
    //判断状态
//    if(globalData->tryLock(TRYLOCKTIME))
//    {
        if(globalData->globalCurrentState == ENUM_COMMAND_RUN || globalData->globalCurrentState == ENUM_COMMAND_CEASE )
        {
//            globalData->unlock();
            return false;//禁止操作
        }
//        globalData->unlock();
//    }

    return true;//允许操作
}

void HomeMenuDelegate::gsoapGetLogFileInfo(QVector<Message> &logInfoList)
{
    int returnFlag;
    std::vector <struct Message > tmpLogInfoList;
    communicateNormalDelegate->getRobotLogFileInfo(globalData->currentRobotID, tmpLogInfoList, returnFlag);
    if(returnFlag == SOAP_OK)
    {
        logInfoList.resize((int)tmpLogInfoList.size());
        for(int i=0; i < (int)tmpLogInfoList.size(); i++)
        {
             logInfoList[i] = tmpLogInfoList[i];
        }
        qDebug() << "HomeMenuDelegate::initDeviceLogView() ==== Gsoap获取日志信息成功!";
    }
    else
    {
        qDebug() << "HomeMenuDelegate::initDeviceLogView() ==== Gsoap获取日志信息失败!";
    }
}

void HomeMenuDelegate::recordPoint_slot()
{
    PointPro currentPositionJointOut;
    globalData->getCurrentArmPosition_joint(currentPositionJointOut);
//    globalData->lock();
    pointList_zeroCalculate.push_back(currentPositionJointOut);
//    globalData->unlock();

    homeMenuView->setZeroPointDialog->updateZeroCalculatePointView(pointList_zeroCalculate);
}

void HomeMenuDelegate::clearPoint_slot()
{
//    globalData->lock();
    pointList_zeroCalculate.pop_back();
//    globalData->unlock();

    homeMenuView->setZeroPointDialog->updateZeroCalculatePointView(pointList_zeroCalculate);
}

void HomeMenuDelegate::calculateZero_slot()
{

    communicateNormalDelegate->calculateZeroOffset(pointList_zeroCalculate,zeroReturnInfo);
    homeMenuView->setZeroPointDialog->updateZeroCalculateResultView(zeroReturnInfo);
}

void HomeMenuDelegate::setZeroOffset_slot()
{
    QMessageBox message(QMessageBox::Question, "提示", "是否使零点偏差生效！"
                        , QMessageBox::Yes|QMessageBox::No , NULL);
    if(message.exec() == QMessageBox::No)
    {
        return;
    }
    int returnInfo;
    communicateNormalDelegate->calibrateRobotByOffset(zeroReturnInfo.zeroOffset,returnInfo);
    zeroReturnInfo.zeroOffset.clear();//防止被重复校准。
    QMessageBox::information(NULL,"提示","零点偏差设置成功",tr("ＯＫ"));
}

void HomeMenuDelegate::getRobotLogFile_Slot(QVector <struct Message> logInfo)
{
    if(!logInfo.isEmpty())
    {
        homeMenuView->deviceLogDialog->message.resize(logInfo.size());
        homeMenuView->deviceLogDialog->message = logInfo;

        //初始化界面空白位置
        homeMenuView->deviceLogDialog->resizeView();

        //往上跟新数据
        homeMenuView->deviceLogDialog->updateView();
    }
}

void HomeMenuDelegate::allowCalibrateJogSlot(bool enable)
{
    emit allowCalibrateJogSignal(enable);
}

void HomeMenuDelegate::calibrateOneAxisSlot(int axisId)
{
    emit calibrateOneAxisSignal(axisId);
}

void HomeMenuDelegate::getCalibrateInformationSlot()
{
    emit getCalibrateInformationSingal();
}

void HomeMenuDelegate::showCalibrateInfo(S_AXISGROUP_ZERO_INFORMATION zeroInformationOut)
{
    homeMenuView->setZeroPointDialog->showCalibrateInfo(zeroInformationOut);
}

void HomeMenuDelegate::passWordCheckSlot(bool isPasswordOk)
{
//    isPasswordCorrectFlag=isPasswordOk;
}

void HomeMenuDelegate::manualChangeBtnSlot(int onOff)
{
    //qDebug()<<onOff;
    emit manualChangeSignal(onOff);
}

void HomeMenuDelegate::setCaliberBtnSlot()
{
    emit setAllCaliberSignal();
    emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("标定完成"));
}

void HomeMenuDelegate::realTimeSlot()
{
    if(motorStatusFlag)
    {
        homeMenuView->motorStatusView->axisCount = globalData->robotAxisCount;//轴数

        int axisCount = homeMenuView->motorStatusView->axisCount;
        homeMenuView->motorStatusView->value0.resize(axisCount+1);
        homeMenuView->motorStatusView->value1.resize(axisCount+1);
        homeMenuView->motorStatusView->value2.resize(axisCount+1);
        homeMenuView->motorStatusView->value3.resize(axisCount+1);
        homeMenuView->motorStatusView->value4.resize(axisCount+1);
//        homeMenuView->motorStatusView->value5.resize(axisCount+1);
//        homeMenuView->motorStatusView->value6.resize(axisCount+1);
//        homeMenuView->motorStatusView->value7.resize(axisCount+1);
//        homeMenuView->motorStatusView->value8.resize(axisCount+1);
//        homeMenuView->motorStatusView->value9.resize(axisCount+1);

        homeMenuView->motorStatusView->valueMax0.resize(axisCount+1);
        homeMenuView->motorStatusView->valueMax1.resize(axisCount+1);
        homeMenuView->motorStatusView->valueMax2.resize(axisCount+1);
        homeMenuView->motorStatusView->valueMax3.resize(axisCount+1);
        homeMenuView->motorStatusView->valueMax4.resize(axisCount+1);
        for(int i = 0;i< axisCount+1;i++)
        {
            homeMenuView->motorStatusView->valueMax0[i] = MIN_INT;
            homeMenuView->motorStatusView->valueMax1[i] = MIN_INT;
            homeMenuView->motorStatusView->valueMax2[i] = MIN_INT;
            homeMenuView->motorStatusView->valueMax3[i] = MIN_INT;
        }
        motorStatusFlag = false;//初始化完成
    }
    else
    {
        if(globalData)
        {
            std::vector<double> axisTorqueOut, axisSpeedOut;
            std::vector<int> axisPositionOut, axisFollowOffsetOut;
            globalData->getMotorInfo(axisTorqueOut, axisSpeedOut,
                                         axisPositionOut, axisFollowOffsetOut);
//            if(globalData->tryLock() )
//            {
//                if(globalData->axisPosition.size()==globalData->robotAxisCount &&
//                   globalData->axisSpeed.size()==globalData->robotAxisCount &&
//                   globalData->axisTorque.size()==globalData->robotAxisCount &&
//                   globalData->axisFollowOffset.size()==globalData->robotAxisCount)
                if(axisPositionOut.size()==homeMenuView->motorStatusView->axisCount)
                {
                    //获取最新值
                    for(int i = 0;i< homeMenuView->motorStatusView->axisCount;i++)
                    {
//                    homeMenuView->motorStatusView->value0[i] = globalData->axisPosition[i];//位置
//                    homeMenuView->motorStatusView->value1[i] = globalData->axisSpeed[i];//速度
//                    homeMenuView->motorStatusView->value2[i] = globalData->axisTorque[i];//力矩
//                    homeMenuView->motorStatusView->value3[i] = globalData->axisFollowOffset[i];//误差
//                    homeMenuView->motorStatusView->value4[i] = globalData->axisFollowOffset[i];//功率

                        //电机位置
                        if(homeMenuView->motorStatusView->value0.size() == axisPositionOut.size()+1)
                        {
                            homeMenuView->motorStatusView->value0[i] = axisPositionOut[i];
                            //qDebug()<<i<<":"<<homeMenuView->motorStatusView->value0[i];
                            if(homeMenuView->motorStatusView->value0[i]<1000 && homeMenuView->motorStatusView->value0[i]>-1000)
                            {
                                homeMenuView->motorStatusView->value0[i] = 0;
                            }
                            else
                            {
                                homeMenuView->motorStatusView->value0[i] = homeMenuView->motorStatusView->value0[i]/100000;
                            }
                        }
                        //轴速度
                        if(homeMenuView->motorStatusView->value1.size() == axisSpeedOut.size()+1)
                        {
                            homeMenuView->motorStatusView->value1[i] = axisSpeedOut[i];
                            if(homeMenuView->motorStatusView->value1[i]<100 && homeMenuView->motorStatusView->value1[i]>-100)
                            {
                                homeMenuView->motorStatusView->value1[i] = 0;
                            }
                            else
                            {
                                homeMenuView->motorStatusView->value1[i] = homeMenuView->motorStatusView->value1[i]/10000;
                            }
                        }
                        //力矩
                        if(homeMenuView->motorStatusView->value2.size() == axisTorqueOut.size()+1)
                        {
                            homeMenuView->motorStatusView->value2[i] = axisTorqueOut[i];
                        }
                        //跟随误差
                        if(homeMenuView->motorStatusView->value3.size() == axisFollowOffsetOut.size()+1)
                        {
                            homeMenuView->motorStatusView->value3[i] = axisFollowOffsetOut[i];
                            if(homeMenuView->motorStatusView->value3[i]<1 && homeMenuView->motorStatusView->value3[i]>-1)
                            {
                                homeMenuView->motorStatusView->value3[i] = 0;
                            }
                            else
                            {
                                homeMenuView->motorStatusView->value3[i] = homeMenuView->motorStatusView->value3[i]/100;
                            }
                        }
                        //功率
                        //if(homeMenuView->motorStatusView->value4.size() == globalData->axisPosition.size()+1)
                        {
                            homeMenuView->motorStatusView->value4[i] = 0;
                        }

//                        globalData->unlock();
                    }

                    //比较大小
                    for(int i = 0;i< homeMenuView->motorStatusView->axisCount;i++)
                    {
                        if(homeMenuView->motorStatusView->value0[i] > homeMenuView->motorStatusView->valueMax0[i])
                        {
                            homeMenuView->motorStatusView->valueMax0[i] = homeMenuView->motorStatusView->value0[i];
                        }

                        if(homeMenuView->motorStatusView->value1[i] > homeMenuView->motorStatusView->valueMax1[i])
                        {
                            homeMenuView->motorStatusView->valueMax1[i] = homeMenuView->motorStatusView->value1[i];
                        }

                        if(homeMenuView->motorStatusView->value2[i] > homeMenuView->motorStatusView->valueMax2[i])
                        {
                            homeMenuView->motorStatusView->valueMax2[i] = homeMenuView->motorStatusView->value2[i];
                        }

                        if(homeMenuView->motorStatusView->value3[i] > homeMenuView->motorStatusView->valueMax3[i])
                        {
                            homeMenuView->motorStatusView->valueMax3[i] = homeMenuView->motorStatusView->value3[i];
                        }

                        if(homeMenuView->motorStatusView->value4[i] > homeMenuView->motorStatusView->valueMax4[i])
                        {
                            homeMenuView->motorStatusView->valueMax4[i] = homeMenuView->motorStatusView->value4[i];
                        }
                    }
                }
                else
                {
                    motorStatusFlag = true;//重新初始化
//                    globalData->unlock();
                    return;
                }
                homeMenuView->motorStatusView->update();
                homeMenuView->motorStatusView->updateView();
//            }
        }
    }
}


void HomeMenuDelegate::startWaveFormSlot()
{
    //qDebug()<<"start";
    timer->start(100);
}

void HomeMenuDelegate::ceaseWaveFormSlot()
{
    //qDebug()<<"cease";
    timer->stop();
}


void HomeMenuDelegate::initToolCoordinateData(QVector<HmiToolCoordinateInformation> recvTool)
{
    homeMenuView->setcoordinatedialog->currentShowCoordinate = 0;

    if(recvTool.size()>0)
    {
        homeMenuView->setcoordinatedialog->toolCoordinateInformation = recvTool;
        homeMenuView->setcoordinatedialog->updateView();
    }
}

void HomeMenuDelegate::initUserCoordinateData(QVector<HmiUserCoordinateInformation> recvUser)
{
    homeMenuView->setcoordinatedialog->currentShowCoordinate = 0;

    if(recvUser.size()>0)
    {
        homeMenuView->setcoordinatedialog->userCoordinateInformation = recvUser;
        homeMenuView->setcoordinatedialog->updateView();
    }
}

void HomeMenuDelegate::reloadCoordinateData()
{
//    if(globalData->tryLock(TRYLOCKTIME))
//    {
        qDebug()<<"coordinate CURRENTid = "<<globalData->currentRobotID;
        emit getCalculateData(globalData->currentRobotID);
//        globalData->unlock();
//    }
}

void HomeMenuDelegate::selectToolCoordinateSlot()
{
    homeMenuView->setcoordinatedialog->currentShowCoordinate = 0;
    homeMenuView->setcoordinatedialog->updateView();
}

void HomeMenuDelegate::selectUserCoordinateSlot()
{
    homeMenuView->setcoordinatedialog->currentShowCoordinate = 1;
    homeMenuView->setcoordinatedialog->updateView();
}

void HomeMenuDelegate::recordPointSlot(int coordinateType, int method, int pointIndex)
{
    //类型 示教类型 点行号
    qDebug()<<"coordinateType "<<coordinateType<<" method "<<method<<" pointIndex "<<pointIndex;
    //qDebug()<<homeMenuView->setcoordinatedialog->toolCoordinateInformation.size();
    //qDebug()<<homeMenuView->setcoordinatedialog->toolCoordinateInformation[coordinateIndex].pointList.size();
    if(globalData)
    {
        //
        PointPro currentPositionJointOut;
        globalData->getCurrentArmPosition_joint(currentPositionJointOut);
        if(coordinateType == 0)
        {
//            if(globalData->tryLock(TRYLOCKTIME))
//            {
                if(ENUM_TOOL_3POINTS == method)
                {
                    homeMenuView->coordinate2Dialog->tmpThreeTool.pointList[pointIndex].positionValue.clear();
                    for(int i = 0;i < currentPositionJointOut.positionValue.size() ;i++)
                    {
                        homeMenuView->coordinate2Dialog->tmpThreeTool.pointList[pointIndex].positionValue.push_back(
                                    currentPositionJointOut.positionValue[i]);
                    }

                    homeMenuView->coordinate2Dialog->tmpThreeTool.pointList[pointIndex].ufValue =
                            currentPositionJointOut.ufValue;
                    homeMenuView->coordinate2Dialog->tmpThreeTool.pointList[pointIndex].utValue =
                            currentPositionJointOut.utValue;
                    homeMenuView->coordinate2Dialog->tmpThreeTool.pointList[pointIndex].recordStatus = 1;//表示已经有示教过

                }
                else if(ENUM_TOOL_6POINTS == method)
                {
                    homeMenuView->coordinate2Dialog->tmpSixTool.pointList[pointIndex].positionValue.clear();
                    for(int i = 0;i < currentPositionJointOut.positionValue.size() ;i++)
                    {
                        homeMenuView->coordinate2Dialog->tmpSixTool.pointList[pointIndex].positionValue.push_back(
                                    currentPositionJointOut.positionValue[i]);
                    }

                    homeMenuView->coordinate2Dialog->tmpSixTool.pointList[pointIndex].ufValue =
                            currentPositionJointOut.ufValue;
                    homeMenuView->coordinate2Dialog->tmpSixTool.pointList[pointIndex].utValue =
                            currentPositionJointOut.utValue;
                    homeMenuView->coordinate2Dialog->tmpSixTool.pointList[pointIndex].recordStatus = 1;//表示已经有示教过
                }
                else if(ENUM_TOOL_20POINTS == method)
                {
                    homeMenuView->coordinate2Dialog->tmpTwentyPointToolInfo.pointList[pointIndex].positionValue.clear();
                    for(int i = 0;i < currentPositionJointOut.positionValue.size() ;i++)
                    {
                        homeMenuView->coordinate2Dialog->tmpTwentyPointToolInfo.pointList[pointIndex].positionValue.push_back(
                                    currentPositionJointOut.positionValue[i]);
                    }

                    homeMenuView->coordinate2Dialog->tmpTwentyPointToolInfo.pointList[pointIndex].ufValue =
                            currentPositionJointOut.ufValue;
                    homeMenuView->coordinate2Dialog->tmpTwentyPointToolInfo.pointList[pointIndex].utValue =
                            currentPositionJointOut.utValue;
                    homeMenuView->coordinate2Dialog->tmpTwentyPointToolInfo.pointList[pointIndex].recordStatus = 1;//表示已经有示教过
                }
                else if(ENUM_TOOL_20POINTS_ZEROCAL == method)
                {
                    homeMenuView->coordinate2Dialog->tmpTwentyPointZeroToolInfo.pointList[pointIndex].positionValue.clear();
                    for(int i = 0;i < currentPositionJointOut.positionValue.size() ;i++)
                    {
                        homeMenuView->coordinate2Dialog->tmpTwentyPointZeroToolInfo.pointList[pointIndex].positionValue.push_back(
                                    currentPositionJointOut.positionValue[i]);
                    }

                    homeMenuView->coordinate2Dialog->tmpTwentyPointZeroToolInfo.pointList[pointIndex].ufValue =
                            currentPositionJointOut.ufValue;
                    homeMenuView->coordinate2Dialog->tmpTwentyPointZeroToolInfo.pointList[pointIndex].utValue =
                            currentPositionJointOut.utValue;
                    homeMenuView->coordinate2Dialog->tmpTwentyPointZeroToolInfo.pointList[pointIndex].recordStatus = 1;//表示已经有示教过
                }
                else if(ENUM_TOOL_23POINTS == method)
                {
                    homeMenuView->coordinate2Dialog->tmpTwentyThreePointToolInfo.pointList[pointIndex].positionValue.clear();
                    for(int i = 0;i < currentPositionJointOut.positionValue.size() ;i++)
                    {
                        homeMenuView->coordinate2Dialog->tmpTwentyThreePointToolInfo.pointList[pointIndex].positionValue.push_back(
                                    currentPositionJointOut.positionValue[i]);
                    }

                    homeMenuView->coordinate2Dialog->tmpTwentyThreePointToolInfo.pointList[pointIndex].ufValue =
                            currentPositionJointOut.ufValue;
                    homeMenuView->coordinate2Dialog->tmpTwentyThreePointToolInfo.pointList[pointIndex].utValue =
                            currentPositionJointOut.utValue;
                    homeMenuView->coordinate2Dialog->tmpTwentyThreePointToolInfo.pointList[pointIndex].recordStatus = 1;//表示已经有示教过
                }

//                globalData->unlock();
//            }
        }
        else if(coordinateType == 1)
        {
//            if(globalData->tryLock(TRYLOCKTIME))
//            {
                if(ENUM_USER_3POINTS == method)
                {
                    homeMenuView->coordinate2Dialog->tmpThreeUser.pointList[pointIndex].positionValue.clear();
                    for(int i = 0;i < currentPositionJointOut.positionValue.size() ;i++)
                    {
                        homeMenuView->coordinate2Dialog->tmpThreeUser.pointList[pointIndex].positionValue.push_back(
                                    currentPositionJointOut.positionValue[i]);
                    }

                    homeMenuView->coordinate2Dialog->tmpThreeUser.pointList[pointIndex].ufValue =
                            currentPositionJointOut.ufValue;
                    homeMenuView->coordinate2Dialog->tmpThreeUser.pointList[pointIndex].utValue =
                            currentPositionJointOut.utValue;
                    homeMenuView->coordinate2Dialog->tmpThreeUser.pointList[pointIndex].recordStatus = 1;//表示已经有示教过

                }
                else if(ENUM_USER_4POINTS == method)
                {
                    homeMenuView->coordinate2Dialog->tmpFourUser.pointList[pointIndex].positionValue.clear();
                    for(int i = 0;i < currentPositionJointOut.positionValue.size() ;i++)
                    {
                        homeMenuView->coordinate2Dialog->tmpFourUser.pointList[pointIndex].positionValue.push_back(
                                    currentPositionJointOut.positionValue[i]);
                    }

                    homeMenuView->coordinate2Dialog->tmpFourUser.pointList[pointIndex].ufValue =
                            currentPositionJointOut.ufValue;
                    homeMenuView->coordinate2Dialog->tmpFourUser.pointList[pointIndex].utValue =
                            currentPositionJointOut.utValue;
                    homeMenuView->coordinate2Dialog->tmpFourUser.pointList[pointIndex].recordStatus = 1;//表示已经有示教过
                }

//                globalData->unlock();
//            }
        }
        else
        {}

        //自己更新自己
        homeMenuView->coordinate2Dialog->updateView(homeMenuView->coordinate2Dialog->currentShowCoordinate,
                                                 homeMenuView->coordinate2Dialog->currentCoordinateIndex);
    }
}

void HomeMenuDelegate::calculateCoordinateSlot(int coordinateType, int coordinateIndex)
{
    //是否允许操作
    if(!operateAllowFlag())
    {
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("机器程序正在运行中\n请点击停止按钮后再操作"));
        return;
    }

    //类型 坐标系行号
    qDebug()<<"coordinateType "<<coordinateType<<" coordinateIndex "<<coordinateIndex;
    int robotID = 0;
//    if(globalData->tryLock(TRYLOCKTIME))
//    {
        robotID = globalData->currentRobotID;
//        globalData->unlock();
//    }
    if(coordinateType == 0)
    {
        qDebug()<<"send TOOL tmpInput";//数据集中于tmpInput
        //qDebug()<<"test TOOL"<<homeMenuView->setcoordinatedialog->editCoordinate->testTool.index;
        //qDebug()<<"test TOOL"<<homeMenuView->setcoordinatedialog->editCoordinate->testTool.method;
        emit sendToolCalculateData(robotID,homeMenuView->setcoordinatedialog->coordinate2Dialog->tmpInputTool);
    }
    else if (coordinateType == 1)
    {
        qDebug()<<"send USER tmpInput";//数据集中于tmpInput
        emit sendUserCalculateData(robotID,homeMenuView->setcoordinatedialog->coordinate2Dialog->tmpInputUser);
    }
    else{}
}

void HomeMenuDelegate::recvCalculateToolDataSlot(HmiToolCoordinateInformation recvTool)
{
    qDebug()<<"recv recvCalculateToolDataSlot ";

    //update 数据
    int size = homeMenuView->setcoordinatedialog->toolCoordinateInformation.size();
    for(int i = 0;i< size;i++)
    {
        if(homeMenuView->setcoordinatedialog->toolCoordinateInformation[i].index == recvTool.index)
        {
            homeMenuView->setcoordinatedialog->toolCoordinateInformation.replace(i,recvTool);

            //update fileData数据 2017.04.18补充
            fileData.toolInfo.replace(i,recvTool);
            break;
        }
    }

    homeMenuView->setcoordinatedialog->syncCoordinateValue();
//    homeMenuView->coordinate2Dialog->updateResult();

    homeMenuView->setcoordinatedialog->on_reloadBtn_clicked();
//    HmiToolCoordinateInformation tmpSixTool;
//    if(recvTool.method != ENUM_TOOL_6POINTS)
//    {
//        tmpSixTool = homeMenuView->editCoordinate->tmpSixTool;//缓存起来
//    }

    //update界面
    //调用 界面一 编辑按钮的槽函数:此处会刷新 界面二
//    homeMenuView->setcoordinatedialog->on_editCoordinate_Btn_clicked();

//    homeMenuView->editCoordinate->tmpSixTool.pointList = tmpSixTool.pointList;//回取
    //自己刷新
//    homeMenuView->setcoordinatedialog->updateView();//view1 存储的数据

//    homeMenuView->editCoordinate->updateError(recvTool.error);
}

void HomeMenuDelegate::recvCalculateUserDataSlot(HmiUserCoordinateInformation recvUser)
{
    qDebug()<<"recv recvCalculateUserDataSlot ";

    //update 数据
    int size = homeMenuView->setcoordinatedialog->userCoordinateInformation.size();
    for(int i = 0;i< size;i++)
    {
        if(homeMenuView->setcoordinatedialog->userCoordinateInformation[i].index == recvUser.index)
        {
            homeMenuView->setcoordinatedialog->userCoordinateInformation.replace(i,recvUser);

            //update fileData数据 2017.04.18补充
            fileData.userInfo.replace(i,recvUser);
            break;
        }
    }


    homeMenuView->setcoordinatedialog->syncCoordinateValue();
//    homeMenuView->coordinate2Dialog->updateResult();

    homeMenuView->setcoordinatedialog->on_reloadBtn_clicked();

//    HmiUserCoordinateInformation tmpFourUser;
//    if(recvUser.method != ENUM_USER_4POINTS)
//    {
//        tmpFourUser = homeMenuView->editCoordinate->tmpFourUser;//缓存起来
//    }

    //update界面
    //调用 界面一 编辑按钮的槽函数:此处会刷新 界面二
//    homeMenuView->setcoordinatedialog->on_editCoordinate_Btn_clicked();

//    homeMenuView->editCoordinate->tmpFourUser = tmpFourUser;//回取
    //自己刷新
//    homeMenuView->setcoordinatedialog->updateView();
}

void HomeMenuDelegate::moveToCoordinatePointPressSlot(MoveParameter tmpPoint)
{
    //类型 坐标系行号 点行号
    qDebug()<<tmpPoint.moveType;
    qDebug()<<tmpPoint.pointType;
    for(int i = 0;i< tmpPoint.targetPoint.positionValue.size();i++)
    {
        qDebug()<<tmpPoint.targetPoint.positionValue[i];
    }

//    emit moveToPointSignal(tmpPoint);
//    moveToPointFlag = true;
    moveOperation->startPointMove(tmpPoint);
}

void HomeMenuDelegate::moveToCoordinatePointReleaseSlot()
{
//    if(moveToPointFlag)
//    {
//        qDebug()<<"stop";
//        emit stopMoveToPointSignal();
//        moveToPointFlag = false;
//    }
    moveOperation->stopPointMove();
}

void HomeMenuDelegate::setToolMass_slot(int toolIndex, double mass, QVector<double> center)
{
    int returnFlag;
    communicateNormalDelegate->setToolMass(toolIndex,mass,center.toStdVector(),returnFlag);
    emit getCalculateData(globalData->currentRobotID);
}

void HomeMenuDelegate::restoreFileSlot(QString restoreFileLocation)
{
    //是否允许操作
    if(!operateAllowFlag())
    {
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("机器程序正在运行中\n请点击停止按钮后再操作"));
        return;
    }

	emit systemCmdRestoreSignal(homeMenuView->fileRestoreDialog->path);
}

void HomeMenuDelegate::showBackupView()
{
    qDebug()<<"show";
    std::vector<CommRobotInfo> robotInfoListOut;
    globalData->getRobotInfoList(robotInfoListOut);
    homeMenuView->fileBackUpDialog->robotList.resize(robotInfoListOut.size());
    if(robotInfoListOut.size()!=robotSize)
    {
        for(int i=0;i<robotInfoListOut.size();i++)
        {
            QString string = QString::fromStdString(robotInfoListOut[i].robotName);
            homeMenuView->fileBackUpDialog->robotList[i].RobotId=robotInfoListOut[i].robotId;
            homeMenuView->fileBackUpDialog->robotList[i].RobotName=string;
        }
    }
    robotSize=robotInfoListOut.size();
    homeMenuView->fileBackUpDialog->updateView();
}

void HomeMenuDelegate::backupFileSlot(int allFlag,int userProgramFlag,int coordinateFlag,int robotConfigFlag,int systemConfigFlag,QVector<RobotBackUpInformation> robot,QString backupLocation)
{
    //是否允许操作
    if(!operateAllowFlag())
    {
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("机器程序正在运行中\n请点击停止按钮后再操作"));
        return;
    }

    qDebug()<<"backupfile";
    qDebug()<<allFlag<<userProgramFlag<<coordinateFlag<<robotConfigFlag<<systemConfigFlag<<backupLocation;

    if(allFlag==1)
    {
        emit systemCmdBackupAllSignal(homeMenuView->fileBackUpDialog->path);
    }
    if(systemConfigFlag==1)
    {
        emit systemCmdBackupGlobalSignal(homeMenuView->fileBackUpDialog->path);
    }
    if(userProgramFlag==1)
    {
        for(int n=0;n<robot.size();n++)
        {
            emit systemCmdBackupProgramSignal(homeMenuView->fileBackUpDialog->path,n);
        }
    }
    if(coordinateFlag==1)
    {
        for(int n=0;n<robot.size();n++)
        {
            emit systemCmdBackupDatSignal(homeMenuView->fileBackUpDialog->path,n);
        }
    }
    if(robotConfigFlag==1)
    {
        for(int n=0;n<robot.size();n++)
        {
            emit systemCmdBackupConfigSignal(homeMenuView->fileBackUpDialog->path,n);
        }
    }
}

void HomeMenuDelegate::registrateSlot(QString regisNum)
{
    qDebug()<<"regisNum="<<regisNum;
    if(regisNum.size() != 30)
    {
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("输入注册码长度不正确\n请重新输入"));
        return;
    }

    emit sendRegistNumToCtrl(regisNum);
}

void HomeMenuDelegate::registrateFromFileSlot(QString fileAddress)
{
    //fileAddress = "/tmp/test.ini";//test

    if(fileAddress == "" || fileAddress.right(3) != "ini")
    {
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("文件路径不正确"));
        return;
    }

    //根据序列号 获取注册码
    QSettings readIni(fileAddress, QSettings::IniFormat);
    QString serialNum = "";

//    if(globalData->tryLock(TRYLOCKTIME))
//    {
        serialNum = QString::fromStdString(globalData->getSerialNumber());
//        globalData->unlock();
//    }

    if(serialNum != "")
    {
        QString regisNum = readIni.value(serialNum).toString();
        QStringList regisNumList = regisNum.split("-");
        if(regisNumList.size() == 6)
        {
            regisNum = regisNumList[0];
            regisNum += regisNumList[1];
            regisNum += regisNumList[2];
            regisNum += regisNumList[3];
            regisNum += regisNumList[4];
            regisNum += regisNumList[5];

            registrateSlot(regisNum);
        }
        else
        {
            emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("文件数据可能不正确,请重试"));
        }
    }
    else
    {
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("请重试"));
    }
}

void HomeMenuDelegate::recvRegistrateResult(ReturnRegisterStatus returnStatus)
{
    if(returnStatus.returnStatus == ENUM_TIME_NORMAL)
    {
//        globalData->lock();
        globalData->globalRegStatus = ENUM_TIME_NORMAL;
//        globalData->unlock();

        homeMenuView->registrationDialog->registrationStatus = tr("注册有效");
        homeMenuView->registrationDialog->expireTime = QString::fromStdString(returnStatus.returnLockTime);
        homeMenuView->registrationDialog->updateView();
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("注册成功"));
    }
    else if(returnStatus.returnStatus == ENUM_TIME_GOING_PASSED)
    {
//        globalData->lock();
        globalData->globalRegStatus = ENUM_TIME_GOING_PASSED;
//        globalData->unlock();

        homeMenuView->registrationDialog->registrationStatus = tr("注册有效(有效时间剩余不足一周)");
        homeMenuView->registrationDialog->expireTime = QString::fromStdString(returnStatus.returnLockTime);
        homeMenuView->registrationDialog->updateView();
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("注册成功\n(有效时间剩余不足一周)"));
    }
    else if(returnStatus.returnStatus == ENUM_TIME_PASSED)
    {
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("注册不成功,有效期已过"));
    }
    else if(returnStatus.returnStatus == ENUM_SERIAL_UNEQUAL)
    {
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("注册不成功,序列号不正确"));
    }
    else if(returnStatus.returnStatus == ENUM_REGISTER_NO_EXIST)
    {
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("注册不成功,注册码不存在"));
    }
}

void HomeMenuDelegate::recvChangePasswordResult(int result)
{
    if(0 == result)
    {
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("密码修改成功"));
        if(homeMenuView->passwordModiyDialog->changeAccount == EM_ACCOUNT_ADMIN)
        {
//            if(globalData->tryLock(TRYLOCKTIME))
//            {
                globalData->setUserPassword(homeMenuView->passwordModiyDialog->newPassword.toStdString());
                homeMenuView->passwordModiyDialog->userPassword = homeMenuView->passwordModiyDialog->newPassword;
//                globalData->unlock();
//            }
        }
    }
    else
    {
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("密码修改失败"));
    }
}

void HomeMenuDelegate::controllerShutDownEnableSlot(bool enable)
{
    emit controllerShutDownEnableSignal(enable);
}

void HomeMenuDelegate::setStartTypeSlot(int type)
{
    //测试
    //shutDownStartSlot(10);
    //发送
    emit sendStartTypeSignal(type);
}

void HomeMenuDelegate::shutDownStartSlot(int s)
{
        //控制器回应允许关机
          if(1==s)
          {
              homeMenuView->startTypeDialog->updateViewShutDown("控制器已经应答关机指令，正在关机...");
                  shutDownS = SHUT_DOWN_TIME;         //设定倒计时

//                  globalData->lock();
                  globalData->ioUpdateFlag = E_UPDATA_TYPE_NONE;       //停止刷新数据,就不会有断线提示了
//                  globalData->unlock();

                  shutDownTimer->start(1000);


//              sleep(3);
//              //关机倒计时
//              QString showInfo;
//              for(int i=0;i<15;i++)
//              {
//                  showInfo="控制器已经应答关机指令，正在关机...倒计时";
//                  showInfo+=i+"秒";
//                  ui->label_info->setText(showInfo);
//                  homeMenuView->startTypeDialog->updateViewShutDown(showInfo);
//                  sleep(1);
//              }
//              system("shutdown -h now");
              //todo
          }
          if(-100==s)
          {
              homeMenuView->startTypeDialog->updateViewShutDown("关机失败，系统设置了禁止关机，请先取消设置！");

              //todo
          }
          if(-101==s)
          {
              homeMenuView->startTypeDialog->updateViewShutDown("关机失败，有用户程序正在运行，请先停机，然后再关机！");

              //todo
          }
          else
          {
              //todo
          }




}

void HomeMenuDelegate::setShutDownSlot()
{
    emit sendShutDownSignal();          //关机指令


}

void HomeMenuDelegate::shutDownStartTimeSlot()
{
    //一秒频率定时器
    shutDownFlag++;
    if(shutDownFlag < shutDownS)
    {
        homeMenuView->startTypeDialog->updateViewShutDown(tr("正在关机...倒计时")
                                                          +QString::number(shutDownS-shutDownFlag)+"秒");
    }
    else
    {
        homeMenuView->startTypeDialog->updateViewShutDown(tr("系统已安全停止，请关闭电源"));

        if(shutDownFlag>(shutDownS+3))
        {
//            system("shutdown -h now");
            system("killall heart.sh");//把心跳关闭
            system("killall hmiMain ;poweroff ");

        }
    }
}

void HomeMenuDelegate::showCurrentRobotMessageSlot()
{
    homeMenuView->deviceLogDialog->showType = 0;
    //getLog();//暂时不刷新
    homeMenuView->deviceLogDialog->updateView();
}

void HomeMenuDelegate::showAllRobotMessageSlot()
{
    homeMenuView->deviceLogDialog->showType = 1;
    //getLog();//暂时不刷新
    homeMenuView->deviceLogDialog->updateView();
}

void HomeMenuDelegate::errorMessageShowOrHideSlot(int errorFlag)
{
    if(1 == errorFlag)
    {
        homeMenuView->deviceLogDialog->errorFlag = 0;
    }
    else if(0 == errorFlag)
    {
        homeMenuView->deviceLogDialog->errorFlag = 1;
    }
    //getLog();//暂时不刷新
    homeMenuView->deviceLogDialog->updateView();
}

void HomeMenuDelegate::warnMessageShowOrHideSlot(int warnFlag)
{
    if(1 == warnFlag)
    {
        homeMenuView->deviceLogDialog->warnFlag = 0;
    }
    else if(0 == warnFlag)
    {
        homeMenuView->deviceLogDialog->warnFlag = 1;
    }
    //getLog();//暂时不刷新
    homeMenuView->deviceLogDialog->updateView();
}

void HomeMenuDelegate::noteMessageShowOrHideSlot(int noteFlag)
{
    if(1 == noteFlag)
    {
        homeMenuView->deviceLogDialog->noteFlag = 0;
    }
    else if(0 == noteFlag)
    {
        homeMenuView->deviceLogDialog->noteFlag = 1;
    }
    //getLog();//暂时不刷新
    homeMenuView->deviceLogDialog->updateView();
}

void HomeMenuDelegate::waitMessageShowOrHideSlot(int waitFlag)
{
    if(1 == waitFlag)
    {
        homeMenuView->deviceLogDialog->waitFlag = 0;
    }
    else if(0 == waitFlag)
    {
        homeMenuView->deviceLogDialog->waitFlag = 1;
    }
    //getLog();//暂时不刷新
    homeMenuView->deviceLogDialog->updateView();
}

void HomeMenuDelegate::startDateChangedSlot(QDate startDate)
{
    //getLog();//暂时不刷新
    if(startDate <= homeMenuView->deviceLogDialog->endDate)
    {
        homeMenuView->deviceLogDialog->startDate = startDate;
    }
    else
    {
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("开始时间不得大于结束时间"));
    }
    homeMenuView->deviceLogDialog->updateView();
}

void HomeMenuDelegate::endDateChangedSlot(QDate endDate)
{
    //getLog();//暂时不刷新
    if(endDate >= homeMenuView->deviceLogDialog->startDate)
    {
        homeMenuView->deviceLogDialog->endDate = endDate;
    }
    else
    {
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("结束时间不得小于开始时间"));
    }
    homeMenuView->deviceLogDialog->updateView();
}

void HomeMenuDelegate::initDeviceLogView()
{
    homeMenuView->deviceLogDialog->startDate.setDate(2016, 11, 01);
    homeMenuView->deviceLogDialog->endDate = QDate::currentDate();
    homeMenuView->deviceLogDialog->selectMessage.operator =(homeMenuView->deviceLogDialog->message);//?有无问题
    homeMenuView->deviceLogDialog->robotName = "";
    homeMenuView->deviceLogDialog->errorFlag = 1;
    homeMenuView->deviceLogDialog->warnFlag = 1;
    homeMenuView->deviceLogDialog->noteFlag = 1;
    homeMenuView->deviceLogDialog->waitFlag = 1;
    homeMenuView->deviceLogDialog->showType = 1;
    //homeMenuView->deviceLogDialog->messageLevelPicture = "/agvwork/AgvHmi/baseBag/hmiProject/resources/DeviceLogRes/error.png";

//    getLog();
    if(GSOAP_OPERATE_PROGRAM_FILE_SWITCH)
    {
        emit requastGetLogInfo_Signal();
    }
    else
    {
        getXmlFileLog(XML_LOG_FILE,homeMenuView->deviceLogDialog->message);
        //初始化界面空白位置
        homeMenuView->deviceLogDialog->resizeView();
        //往上跟新数据
        homeMenuView->deviceLogDialog->updateView();
    }
}

void HomeMenuDelegate::getLog()
{
    QString logName = LOG_FILE;
    QFile file(logName);

    quint32 tmpSize;
    if(file.exists())
    {
        if(file.open(QIODevice::ReadOnly))
        {
             QDataStream out(&file);
             out.setVersion(QDataStream::Qt_4_6);
             out >> tmpSize;

             homeMenuView->deviceLogDialog->message.resize(tmpSize);

             int tmpInt;
             qint64 timeInt;
             //long tmpLong;
             QString tmpStr;

             for(int i = 0; i < homeMenuView->deviceLogDialog->message.size();i++)
             {
                 out >> tmpInt;
                 homeMenuView->deviceLogDialog->message[i].MessageLevel = tmpInt;
                 //qDebug() << "------level-----"<<tmpInt;

                 //out >> tmpStr;
                 out >> timeInt;//以后需要修改成这个,新版消息
                 homeMenuView->deviceLogDialog->message[i].time = timeInt;
                 //qDebug() << i << "------time------"<< timeInt;

                 out >> tmpInt;
                 homeMenuView->deviceLogDialog->message[i].robotId = tmpInt;
                 //qDebug() << i << "------robotId---"<<tmpInt;

                 out >> tmpStr;
                 homeMenuView->deviceLogDialog->message[i].componentClassName = tmpStr.toStdString();

                 out >> tmpStr;
                 homeMenuView->deviceLogDialog->message[i].messageType = tmpStr.toStdString();

                 out >> tmpInt;
                 homeMenuView->deviceLogDialog->message[i].messageCode = tmpInt;

                 out >> tmpInt;
                 homeMenuView->deviceLogDialog->message[i].parameter1 = tmpInt;

                 out >> tmpInt;
                 homeMenuView->deviceLogDialog->message[i].parameter2 = tmpInt;

                 out >> tmpInt;
                 homeMenuView->deviceLogDialog->message[i].parameter3 = tmpInt;

                 out >> tmpInt;
                 homeMenuView->deviceLogDialog->message[i].parameter4 = tmpInt;

                 out >> tmpStr;
                 homeMenuView->deviceLogDialog->message[i].MessageInformation = tmpStr.toStdString();
                 //qDebug() << i << "------info------"<<tmpStr;
             }

             file.close();//注意关闭文件
        }
    }
    else
    {
        //消息预留
        //日志文件不存在
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("日志文件不存在"));
    }
}

void HomeMenuDelegate::getXmlFileLog(QString xmlLogFileName,QVector <Message> &messageOut)
{
    DomParser domParser;
    bool ok = domParser.openXml(xmlLogFileName, QIODevice::ReadOnly );
    if( !ok )
    {
       qDebug()<<"error no log file";
       emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("日志文件不存在"));
       return ;
    }

    QDomNode  mainNode = domParser.findSubNode(domParser.getRootDomElement(), "log", ok );
    if( !ok )
    {
       qDebug()<<"error no log node";
       return ;
    }

    QDomNodeList devNodes = mainNode.childNodes();
    messageOut.resize(devNodes.size());

    for (int i=0;i<devNodes.size();i++)
    {

       // 读取日子文件节点内容
       domParser.readXml( domParser.findSubNode(devNodes.at(i), "messageLevel", ok ), messageOut[i].MessageLevel );
       domParser.readXml( domParser.findSubNode(devNodes.at(i), "timeLong", ok ), messageOut[i].time );
       domParser.readXml( domParser.findSubNode(devNodes.at(i), "robotId", ok ), messageOut[i].robotId );
       domParser.readXml( domParser.findSubNode(devNodes.at(i), "componentClassName", ok ),
                          messageOut[i].componentClassName );
       domParser.readXml( domParser.findSubNode(devNodes.at(i), "messageType", ok ), messageOut[i].messageType );
       domParser.readXml( domParser.findSubNode(devNodes.at(i), "messageCode", ok ), messageOut[i].messageCode );
       domParser.readXml( domParser.findSubNode(devNodes.at(i), "parameter1", ok ), messageOut[i].parameter1 );
       domParser.readXml( domParser.findSubNode(devNodes.at(i), "parameter2", ok ), messageOut[i].parameter2 );
       domParser.readXml( domParser.findSubNode(devNodes.at(i), "parameter3", ok ), messageOut[i].parameter3 );
       domParser.readXml( domParser.findSubNode(devNodes.at(i), "parameter4", ok ), messageOut[i].parameter4 );
       domParser.readXml( domParser.findSubNode(devNodes.at(i), "messageInformation", ok ),
                          messageOut[i].MessageInformation );

    }

    domParser.closeXml();
}

void HomeMenuDelegate::setHmiIpSlot(QVector<int> hmiIp,QVector<int> hmiGateway,QVector<int> hmiDNS)
{
    //是否允许操作
    if(!operateAllowFlag())
    {
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("机器程序正在运行中\n请点击停止按钮后再操作"));
        return;
    }

    //qDebug() << "set Hmi Ip" << hmiIp[0] << "." << hmiIp[1] << "." << hmiIp[2] << "." << hmiIp[3];
    QString ip;
    QString gateway;
    QString dns;
    if(hmiIp.size() == 4 && hmiGateway.size() == 4 && hmiDNS.size() == 4)
    {
        ip = QString::number(hmiIp[0]) + "."+
                QString::number(hmiIp[1]) + "."+
                QString::number(hmiIp[2]) + "."+
                QString::number(hmiIp[3]);
        gateway = QString::number(hmiGateway[0]) + "."+
                QString::number(hmiGateway[1]) + "."+
                QString::number(hmiGateway[2]) + "."+
                QString::number(hmiGateway[3]);
        dns = QString::number(hmiDNS[0]) + "."+
                QString::number(hmiDNS[1]) + "."+
                QString::number(hmiDNS[2]) + "."+
                QString::number(hmiDNS[3]);

        qDebug() << "set Hmi Ip " << ip;
        qDebug() << "set Hmi gateway " << gateway;
        qDebug() << "set Hmi dns " << dns;

        //写入ini文件
        writeIniCtrlIP("HmiIP",ip,gateway,dns);//保存示教器IP

        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("示教器IP修改成功\n重启后生效"));
    }
}

void HomeMenuDelegate::setControllerIpSlot(QVector<int> ctrlIp, QVector<int> ctrlGateway, QVector<int> ctrlDNS)
{
    //是否允许操作
    if(!operateAllowFlag())
    {
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("机器程序正在运行中\n请点击停止按钮后再操作"));
        return;
    }

    QString ip;
    QString gateway;
    QString dns;
    if(ctrlIp.size() == 4)
    {
        ip = QString::number(ctrlIp[0]) + "."+
                QString::number(ctrlIp[1]) + "."+
                QString::number(ctrlIp[2]) + "."+
                QString::number(ctrlIp[3]);
        gateway = QString::number(ctrlGateway[0]) + "."+
                QString::number(ctrlGateway[1]) + "."+
                QString::number(ctrlGateway[2]) + "."+
                QString::number(ctrlGateway[3]);
        dns = QString::number(ctrlDNS[0]) + "."+
                QString::number(ctrlDNS[1]) + "."+
                QString::number(ctrlDNS[2]) + "."+
                QString::number(ctrlDNS[3]);

        qDebug() << "set Controller Ip " << ip;
        qDebug() << "set Controller gateway " << gateway;
        qDebug() << "set Controller dns " << dns;

        //发送到控制器
        ControllerIpGroupInfo info;
        info.ipAddress = ip.toStdString();
        info.gateWay = gateway.toStdString();
        info.dnsServer = dns.toStdString();
        emit sendCtrlSetIP(info);//待测试

        writeIniCtrlIP("CtrlIP",ip,gateway,dns);//保存控制器IP
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("控制器IP修改成功\n重启后生效"));
    }
}

void HomeMenuDelegate::writeIniCtrlIP(QString type, QString ip, QString gateway, QString dns)
{
    QSettings settings(CTRL_IP_INI_PATH, QSettings::IniFormat); // 当前目录的INI文件
    settings.beginGroup(type);//CtrlIP? HmiIP?
    settings.setValue("ip", ip);
    //settings.setValue("port", port);
    //settings.setValue("netmask", netmask);
    settings.setValue("gateway", gateway);
    settings.setValue("dns", dns);
    settings.endGroup();
}

void HomeMenuDelegate::modifySlot()
{
    qDebug()<<"accept "<<homeMenuView->passwordModiyDialog->changeAccount;
    emit passwordChangeSignal(homeMenuView->passwordModiyDialog->changeAccount,homeMenuView->passwordModiyDialog->userPassword,homeMenuView->passwordModiyDialog->newPassword);
    //emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("修改成功"));
}

void HomeMenuDelegate::hmiUpdatePathSlot(QString path)
{
    //todo
//    //是否允许操作
//    if(!operateAllowFlag())
//    {
//        homeMenuView->restoreCheckDialog->hide();
//        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("机器程序正在运行中\n请点击停止按钮后再操作"));
//        return;
//    }

//    //判断地址
//    if(path == "")
//    {
//        homeMenuView->restoreCheckDialog->hide();
//        emit msgBoxSignal(EM_MSG_BOX_NO_BTN,tr("提示"),tr("文件地址不能为空"));
//        return;
//    }

//    QString cmd = "cp " + path +" /agvwork";
//    QByteArray cmdArray = cmd.toUtf8();
//    if(0 == system(cmdArray.data()))
//    {
//        homeMenuView->restoreCheckDialog->hide();
//        emit msgBoxSignal(EM_MSG_BOX_NO_BTN,tr("提示"),tr("示教器升级完成\n请重启生效"));
//    }
//    else
//    {
//        homeMenuView->restoreCheckDialog->hide();
//        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("升级失败"));
//    }
}

void HomeMenuDelegate::ctrlUpdatePathSlot(QString path)
{
    //todo
//    //是否允许操作
//    if(!operateAllowFlag())
//    {
//        homeMenuView->restoreCheckDialog->hide();
//        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("机器程序正在运行中\n请点击停止按钮后再操作"));
//        return;
//    }

//    //判断地址
//    if(path == "")
//    {
//        homeMenuView->restoreCheckDialog->hide();
//        emit msgBoxSignal(EM_MSG_BOX_NO_BTN,tr("提示"),tr("文件地址不能为空"));
//        return;
//    }

//    bool flag = false;
//    //建立 备份中转站
//    QString cmd = "mkdir " + QString(TMP_COPY_PATH);
//    QByteArray cmdArray = cmd.toUtf8();
//    system(cmdArray.data());

//    //先备份当前的程序文件,以防被覆盖
//    cmd = "cp " + QString(PROGRAM_PATH) +"* " + QString(TMP_COPY_PATH);
//    cmdArray = cmd.toUtf8();
//    system(cmdArray.data());

//    //升级解压
//    cmd = "unzip -o " + path + " -d /agvwork/AgvFundation/fundation/";
//    cmdArray = cmd.toUtf8();
//    if(0 == system(cmdArray.data()))
//    {
//        flag = true;
//    }

//    //恢复程序文件内容
//    cmd = "cp " + QString(TMP_COPY_PATH) + "* " + QString(PROGRAM_PATH);
//    cmdArray = cmd.toUtf8();
//    system(cmdArray.data());

//    //删除 备份中转站
//    cmd = "rm -rf " + QString(TMP_COPY_PATH);
//    cmdArray = cmd.toUtf8();
//    system(cmdArray.data());

//    if(flag)
//    {
//        homeMenuView->restoreCheckDialog->hide();
//        emit msgBoxSignal(EM_MSG_BOX_NO_BTN,tr("提示"),tr("控制器升级完成\n请重启生效"));
//    }
//    else
//    {
//        homeMenuView->restoreCheckDialog->hide();
//        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("还原失败"));
//    }
}

void HomeMenuDelegate::hmiRestoreSlot()
{
    //是否允许操作
    if(!operateAllowFlag())
    {
        homeMenuView->restoreCheckDialog->hide();
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("机器程序正在运行中\n请点击停止按钮后再操作"));
        return;
    }

    //检查文件是否存在
    QFile file(RESTORE_HMI_FILE);
    if (!file.exists())
    {
        homeMenuView->restoreCheckDialog->hide();
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("还原文件不存在\n无法还原"));
        return;
    };

    QString cmd = "cp " + QString(RESTORE_HMI_FILE) +" /root/hmiPackage.zip";
    QByteArray cmdArray = cmd.toUtf8();
    if(0 == system(cmdArray.data()))
    {
        homeMenuView->restoreCheckDialog->hide();
        emit msgBoxSignal(EM_MSG_BOX_NO_BTN,tr("提示"),tr("示教器还原完成\n请重启生效"));
    }
    else
    {
        homeMenuView->restoreCheckDialog->hide();
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("还原失败"));
    }
}

void HomeMenuDelegate::ctrlRestoreSlot()
{
    //是否允许操作
    if(!operateAllowFlag())
    {
        homeMenuView->restoreCheckDialog->hide();
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("机器程序正在运行中\n请点击停止按钮后再操作"));
        return;
    }

    //检查文件是否存在
    QFile file(RESTORE_CTRL_FILE);
    if (!file.exists())
    {
        homeMenuView->restoreCheckDialog->hide();
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("还原文件不存在\n无法还原"));
        return;
    };

    bool flag = false;
    //备份中转站
    QString cmd = "mkdir " + QString(TMP_COPY_PATH);
    QByteArray cmdArray = cmd.toUtf8();
    system(cmdArray.data());

    //先备份当前的程序文件,以防被覆盖
    cmd = "cp " + QString(PROGRAM_PATH) +"* " + QString(TMP_COPY_PATH);
    cmdArray = cmd.toUtf8();
    system(cmdArray.data());

    //升级解压
    cmd = "unzip -o " + QString(RESTORE_CTRL_FILE) + " -d /agvwork/AgvFundation/fundation/";
    cmdArray = cmd.toUtf8();
    if(0 == system(cmdArray.data()))
    {
        flag = true;
    }

    //恢复程序文件内容
    cmd = "cp " + QString(TMP_COPY_PATH) + "* " + QString(PROGRAM_PATH);
    cmdArray = cmd.toUtf8();
    system(cmdArray.data());

    //删除 备份中转站
    cmd = "rm -rf " + QString(TMP_COPY_PATH);
    cmdArray = cmd.toUtf8();
    system(cmdArray.data());

    if(flag)
    {
        homeMenuView->restoreCheckDialog->hide();
        emit msgBoxSignal(EM_MSG_BOX_NO_BTN,tr("提示"),tr("控制器还原完成\n请重启生效"));
    }
    else
    {
        homeMenuView->restoreCheckDialog->hide();
        emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("还原失败"));
    }
}

void HomeMenuDelegate::setMotorDcModeSlot(int value)
{
    emit setMotorDcModeSignal(value);
}

void HomeMenuDelegate::clearMotorBatteryErrorSlot()
{
    emit clearMotorBatteryErrorSignal();
}

void HomeMenuDelegate::showEthercatSlavesInformationSlot(std::vector<EcatBusDevInfo_gsoap> slavesInfo)
{
    homeMenuView->ethercatDevicefigDlg->showEthercatDeviceInfo(slavesInfo);
}

void HomeMenuDelegate::writeEthercatDeviceAliasSlot(int nodeId, int alias)
{
    emit writeEthercatDeviceAliasSignal(nodeId,alias);
}

void HomeMenuDelegate::getEthercatSlavesInformationSlot()
{
    emit getEthercatSlavesInformationSignal();
}

void HomeMenuDelegate::showDebugInfo_motionServerSlot(MotionDebugInfo info)
{
    homeMenuView->debugInfoDlg->showDebugInfo_motionServer(info);
}

void HomeMenuDelegate::showDebugInfo_programEngineSlot(ProgramEngineDebugInfo info)
{
    homeMenuView->debugInfoDlg->showDebugInfo_programEngine(info);
}

void HomeMenuDelegate::showDebugInfo_programEngineSlot(std::vector<ProgramEngineDebugInfo> info)
{
    homeMenuView->debugInfoDlg->showDebugInfo_programEngine(info);
}

void HomeMenuDelegate::showTaskInfoSlot(TaskManagerInfo info)
{
    homeMenuView->debugInfoDlg->showDebugInfo_taskInfo(info);
}

void HomeMenuDelegate::getPogramEngineDebugInfoSlot()
{
    emit getPogramEngineDebugInfoSignal();
}

void HomeMenuDelegate::getMotionEngineDebugInfoSlot()
{
    emit getMotionEngineDebugInfoSignal();
}

void HomeMenuDelegate::getTaskInfoSlot()
{
    emit getTaskInfoSignal();
}

void HomeMenuDelegate::showDebugDlgSlot()
{

    homeMenuView->debugInfoDlg->show();

}

void HomeMenuDelegate::changeLanguageSlot(int language)
{
    if(1 == language)
    {
        translator.load("/agvwork/AgvHmi/baseBag/hmiProject/language/menuDelEnglishLan.qm");
        qApp->installTranslator(&translator);
    }
    else
    {
        qApp->removeTranslator(&translator);
    }
    homeMenuView->changeLanguage(language);
}

//void HomeMenuDelegate::getLogFileDirSlot(QHash<QString, bool> logFileList, const QString &logFileFtpDirectory, const QString &logFileClientPath)
//{
//        qDebug() << "Download Login File List Success, Path :" << logFileFtpDirectory;

//        if(fileData.ftpOperateNum != EM_FTP_OPERATE_LOGIN)
//        {
//            return;
//        }
////        // 文件模块使用标识
////        if(fileData.fileManageFlag)
////        {
////            return;
////        }
////        if(fileData.getMapFileInfoFlag)
////        {
////            return;
////        }

////        if(fileData.getMusicFileInfoFlag)
////        {
////            return;
////        }

////        if(ftpManage->isLoginDirFlag())                 // 是否是登录文件 true
////        {
////            return;
////        }
//        for(int i = 0; i < logFileList.keys().count(); i++)
//        {
//            if(!logFileList.values().at(i))
//            {
//                logFileNameList << logFileList.keys().at(i);
//            }
//        }
//        clientPathTmp = logFileClientPath;
//        serverPathTmp = logFileFtpDirectory;
//        currentFileIndex = 0;

//        ftpManage->ftpGetFile(logFileNameList.at(currentFileIndex), logFileClientPath, logFileFtpDirectory);
//}

//void HomeMenuDelegate::getFileSlot(bool status, QString message)
//{
//    if(fileData.ftpOperateNum != EM_FTP_OPERATE_LOGIN)
//    {
//        return;
//    }
////    if(ftpManage->isLoginDirFlag())
////    {
////        return;
////    }
//    if(status)
//    {
//        currentFileIndex++;
//        if(currentFileIndex < logFileNameList.count())
//        {
//            ftpManage->ftpGetFile(logFileNameList.at(currentFileIndex), clientPathTmp, serverPathTmp);
//        }
//        else
//        {
//            currentFileIndex = 0;
//            logFileNameList.clear();
////            ftpManage->setGetDirFlag(true);
////            ftpManage->setLoginFileGetFlag(true);
//            fileData.ftpOperateNum = EM_FTP_OPERATE_CLOSE;
//        }
//    }
//}

void HomeMenuDelegate::setEditLanguageChangeMenu(int id)
{
    for(int i = 0;i<2;i++)
    {
        QString tmp = homeMenuView->languageAction[i]->text();
        tmp.replace(QRegExp(" √"),"");
        homeMenuView->languageAction[i]->setText(tmp);

        if(i == id)
        {
            homeMenuView->languageAction[id]->setText(tmp + " √");
        }

    }
}

